package com.tqjc.system.system.controller;

import com.tqjc.system.common.controller.BaseController;
import com.tqjc.system.common.entity.BO.AddTaskCacheInfoBO;
import com.tqjc.system.common.entity.VO.AreaInfoVO;
import com.tqjc.system.common.enums.CacheInfoEnum;
import com.tqjc.system.core.model.AjaxJson;
import com.tqjc.system.core.util.ResponseUtil;
import com.tqjc.system.system.entity.SysAreaInfoEntity;
import com.tqjc.system.system.wrapper.AddTaskCacheInfoWrapper;
import com.tqjc.system.system.wrapper.AreaManageWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @description: 缓存管理控制层
 * @Author: 86195
 * @Date: 2024/1/30 17:23
 **/
@RequestMapping("/sys/cache")
@Controller
@Slf4j
public class SysCacheManageController extends BaseController {


    @RequestMapping("/index")
    public String cacheIndex(){
        return "sys/manage/cacheManage.html";
    }



    @RequestMapping("/infoList")
    public void cacheInfo(String cacheType, HttpServletResponse response){
        try {

            log.info("查询缓存信息开始");
            CacheInfoEnum cacheInfoEnum = CacheInfoEnum.getCacheInfoEnumById(cacheType);
            if(cacheInfoEnum == null){
                log.error("缓存id未找到对应的缓存类型枚举");
                return;
            }
            List<AddTaskCacheInfoBO> addTaskCacheInfoList = cacheInfoEnum.getAddTaskCacheInfoList();
            ResponseUtil.write(response, new AddTaskCacheInfoWrapper(addTaskCacheInfoList).wrap());
            log.info("查询缓存信息结束");
        } catch (Exception e){
            log.error("查询缓存信息结束运行异常",e);
        }
    }


    @RequestMapping("/update")
    @ResponseBody
    public AjaxJson updateCacheInfo(String cacheType,String cacheValue,String cacheKey){
        log.info("修改缓存信息开始");
        AjaxJson ajaxJson = new AjaxJson();
        CacheInfoEnum cacheInfoEnum = CacheInfoEnum.getCacheInfoEnumById(cacheType);
        cacheInfoEnum.updateInfo(cacheKey,cacheValue);
        log.info("修改缓存信息结束");
        ajaxJson.setMsg("操作成功！！");
        return ajaxJson;

    }

}
